package org.robot.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jsoup.helper.StringUtil;
import org.jsoup.select.Elements;
import org.robot.component.Page;
import org.robot.dao.IssueDao;
import org.robot.pojo.Author;
import org.robot.pojo.Issue;
import org.robot.pojo.Paper;
import org.robot.pojo.PaperDoc;
import org.robot.pojo.PaperInfo;

public class ParseUtil {
	private static Log log = LogFactory.getLog(ParseUtil.class);
	
	public static final String PDFURL = "pdfUrl";

	/**
	 * 北京勤云科技
	 * @author pdz
	 * @date 2019年2月12日
	 * @param page
	 * @param taskid
	 * @return
	 */
	public static PaperInfo parsePaperInfo1(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper1(page, taskid, issueid);
		List<Author> authorList = parseAuthor1(page, taskid);
		List<PaperDoc> paperdocList = parsePaperDoc1(page, taskid);
		return new PaperInfo(paper, authorList, paperdocList);
	}
	
	/**
	 * 北京玛格泰克
	 * @author pdz
	 * @date 2019年2月18日
	 */
	public static PaperInfo parsePaperInfo2(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper2(page, taskid, issueid);
		List<Author> authorList = parseAuthor2(page, taskid);
		List<PaperDoc> paperdocList = parsePaperDoc2(page, taskid);
		return new PaperInfo(paper, authorList, paperdocList);
	}
	
	/**
	 * 北京玛格泰克，paper却只有标题和摘要
	 * @author pdz
	 * @date 2019年2月22日
	 * @param page
	 * @param taskid
	 * @return
	 */
	public static PaperInfo parsePaperInfo4(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper4(page, taskid, issueid);
		return new PaperInfo(paper);
	}
	
	/**
	 * 铁道科学与工程学报
	 * @author pdz
	 * @date 2019年2月19日
	 * @return
	 */
	public static PaperInfo parsePaperInfo3(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper3(page, taskid, issueid);
		List<Author> authorList = parseAuthor3(page, taskid);
		List<PaperDoc> paperdocList = null;
		return new PaperInfo(paper, authorList, paperdocList);
	}
	
	/**
	 * 地球科学在线
	 * @author pdz
	 * @date 2019年2月26日
	 * @return
	 */
	public static PaperInfo parsePaperInfo5(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper5(page, taskid, issueid);
		List<Author> authorList = parseAuthor5(page, taskid);
		List<PaperDoc> paperdocList = null;
		return new PaperInfo(paper, authorList, paperdocList);
	}
	
	/**
	 * 玛格泰克,meta中没有信息的
	 * @author pdz
	 * @date 2019年2月27日
	 * @return
	 */
	public static PaperInfo parsePaperInfo6(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper6(page, taskid, issueid);
		List<Author> authorList = parseAuthor6(page, taskid);
		List<PaperDoc> paperdocList = null;
		return new PaperInfo(paper, authorList, paperdocList);
	}
	
	/**
	 * 陕西师范大学学报自然科学版
	 * @author pdz
	 * @date 2019年2月28日
	 * @return
	 */
	public static PaperInfo parsePaperInfo7(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper7(page, taskid, issueid);
		List<Author> authorList = parseAuthor7(page, taskid);
		List<PaperDoc> paperdocList = null;
		return new PaperInfo(paper, authorList, paperdocList);
	}
	
	/**
	 * 西南大学学报
	 * @author pdz
	 * @date 2019年2月28日
	 * @return
	 */
	public static PaperInfo parsePaperInfo8(Page page, Long taskid) {
		Long issueid = IssueDao.selectPidByWebsite(Issue.class, page.prevUrl(), taskid);
		Paper paper = parsePaper8(page, taskid, issueid);
		List<Author> authorList = null;
		List<PaperDoc> paperdocList = parsePaperDoc8(page, taskid);
		return new PaperInfo(paper, authorList, paperdocList);
	}
	
	/**
	 * 用于解析北京玛格泰克科技发展有限公司设计开发的网站
	 * @author pdz
	 * @date 2019年2月2日
	 * @param page
	 * @param taskid
	 * @param paperid
	 * @return
	 */
	private static List<PaperDoc> parsePaperDoc2(Page page, Long taskid) {
		try {
			List<String> references = null;
			String refs = page.select("div#reference_tab_content table tr td p").html();
			if (!StringUtil.isBlank(refs)) {
				String[] refArr = refs.split("<br>");
				references = Arrays.asList(refArr);
			} else {
				references = page.select("div#reference_tab_content table tr").eachText();
			}
			page.put("references", references);
			List<PaperDoc> paperDocList = references.stream().filter(ref -> !StringUtil.isBlank(ref)).map(text -> {
				PaperDoc paperDoc = new PaperDoc();
				paperDoc.setDocname(text);
				paperDoc.setTaskid(taskid);
				return paperDoc;
			}).collect(Collectors.toList());
			return paperDocList;
		} catch (Exception e) {
			log.error(page.url(), e);
		}
		return null;
	}

	/**
	 * 用于解析北京玛格泰克科技发展有限公司设计开发的网站
	 * @author pdz
	 * @date 2019年2月2日
	 * @param page
	 * @param taskid
	 * @param paperid
	 * @return
	 */
	private static List<Author> parseAuthor2(Page page, Long taskid) {
		try {
			List<String> authorList = page.select("meta[name=DC.Contributor]").eachAttr("content");
			String[] auts = authorList.toArray(new String[authorList.size()]);
			String autEmailStr = page.select("span.J_zhaiyao").text();
			List<Author> list = new LinkedList<>();
			Map<String, String> autEmailMap = Utils.autEmailMap(autEmailStr, auts, "\\d");
			autEmailMap.forEach((aut, email) -> {
				Author author = new Author();
				author.setFullName(aut);
				author.setEmail(email);
				author.setTaskId(taskid);
				list.add(author);
			});
			return list;
		} catch (Exception e) {
//			log.error(page.url(), e);
		}
		return null;
	}

	/**
	 * 用于解析北京玛格泰克科技发展有限公司设计开发的网站
	 * @author pdz
	 * @date 2019年2月2日
	 * @param page
	 * @param taskid
	 * @param issueid
	 * @return
	 */
	private static Paper parsePaper2(Page page, Long taskid, Long issueid) {
		try {
			String doi = page.select("meta[name=citation_doi]").attr("content");
			String startPage = page.select("meta[name=citation_firstpage]").attr("content");
			String endPage = page.select("meta[name=citation_lastpage]").attr("content");
			String fileUrl = page.select("meta[name=citation_pdf_url]").attr("content");
			String authors = String.join("<br>", page.select("meta[name=citation_authors]").eachAttr("content"));
			String keywords = String.join("<br>", page.select("meta[name=DC.Keywords]").eachAttr("content"));
			String title = String.join("<br>", page.select("meta[name=citation_title]").eachAttr("content"));
			String affs = ""; 
			Elements affEles = page.select("td.J_author_cn");
			if (!affEles.isEmpty())
				affs = affEles.first().parent().nextElementSibling().text();
			String abstCn = page.select(".J_zhaiyao:has(b:contains(摘要))").text().replaceFirst("(摘要)+", "").replaceFirst(":+", "").trim();
			String abstEn = page.select(".J_zhaiyao:has(b:contains(Abstract))").text().replaceFirst("(Abstract)+", "").replaceFirst(":+", "").trim();
			String abst = String.join("<br>", abstCn, abstEn);
			
			Paper paper = new Paper();
			paper.setWebsite(page.url());
			paper.setTitle(title);
			paper.setTaskid(taskid);
			paper.setDoi(doi);
			paper.setAbstracts(abst);
			paper.setPdfUrl(fileUrl);
			paper.setAuthors(authors);
			paper.setAffilications(affs);
			paper.setKeywords(keywords);
			paper.setPage(startPage + "-" + endPage);
			paper.setIssueId(issueid);
			putInfo(page, paper);
			return paper;
		} catch (Exception e) {
			log.error(page.url(), e);
		}
		return null;
	}
	
	public static void main(String[] args) {
		IntStream.iterate(0, i -> i+2).limit(20).filter(i -> i < 9).forEach(System.out::println);
	}
	/**
	 * 北京勤云科技制作的网站
	 * @author pdz
	 * @date 2019年2月2日
	 * @param page
	 * @param taskid
	 * @param paperid
	 * @return
	 */
	private static List<PaperDoc> parsePaperDoc1(Page page, Long taskid) {
		List<PaperDoc> paperDocList = page.select("#ReferenceList table tr:gt(0), #RelateArticleList table tr:gt(0)").eachText().stream()
			.map(ref -> {
				PaperDoc paperDoc = new PaperDoc();
				paperDoc.setDocname(ref.trim());
				paperDoc.setTaskid(taskid);
				return paperDoc;
			}).collect(Collectors.toList());
		return paperDocList;
	}
	
	/**
	 * 勤云科技
	 * @author pdz
	 * @date 2019年2月12日
	 * @param page
	 * @param taskid
	 * @param paperid
	 * @return
	 */
	private static List<Author> parseAuthor1(Page page, Long taskid) {
//		List<String> authorList = page.select("meta[name=citation_author]").eachAttr("content");
		List<String> authorList = page.select("span#Author table tr td:eq(0) a").eachText().stream().map(aut -> aut.replaceAll("\\*|\\d", "")).collect(Collectors.toList());
		String[] auts = authorList.toArray(new String[authorList.size()]);
		String autEmailStr = page.select("span#Author table").text();
		List<Author> list = new LinkedList<>();
		Map<String, String> autEmailMap = Utils.autEmailMap(autEmailStr, auts, "\\d");
		autEmailMap.forEach((aut, email) -> {
			Author author = new Author();
			author.setFullName(aut);
			author.setEmail(email);
			author.setTaskId(taskid);
			list.add(author);
		});
		return list;
	}

	
	/**
	 * 北京勤云科技制作的网站
	 * @author pdz
	 * @date 2019年2月2日
	 * @param page
	 * @return
	 */
	private static Paper parsePaper1(Page page, Long taskid, Long issueid) {
		String refText = page.select("span#ReferenceText").text();
		String pages = RegexUtil.regexFirst("\\d+[-~]\\d+", refText); 
		if (!StringUtil.isBlank(pages))
			pages = pages.replace("~", "-");
		String title = joinText(page, "#FileTitle, #EnTitle");
		String doi = page.select("span#DOI a").text().replace("DOI", "").replace(":", "").trim();
		String keywords = joinText(page, "span#KeyWord, span#EnKeyWord");
		List<String> authorList = page.select("span#Author table tr td:eq(0) a").eachText().stream().map(aut -> aut.replaceAll("\\*|\\d", "")).collect(Collectors.toList());
		String authors = String.join(",", authorList);
		List<String> affList = page.select("span#Author table tr td:eq(1) a").eachText();
		String affs = String.join(",", affList);
		String abst = joinText(page, "span#Abstract, span#EnAbstract");
		String fileUrl = page.select("span#URL a").first().absUrl("href");
		
		Paper paper = new Paper();
		paper.setWebsite(page.url());
		paper.setTitle(title);
		paper.setTaskid(taskid);
		paper.setDoi(doi);
		paper.setAbstracts(abst);
		paper.setPdfUrl(fileUrl);
		paper.setAuthors(authors);
		paper.setAffilications(affs);
		paper.setKeywords(keywords);
		paper.setPage(pages);
		paper.setIssueId(issueid);
		putInfo(page, paper);
		return paper;
	}


	public static void putInfo(Page page, Paper paper) {
		page.put("title", paper.getTitle());
		page.put("authorName", paper.getAuthors());
		page.put("keywords", paper.getKeywords());
		page.put("paperAbstract", paper.getAbstracts());
//		page.put("fileName", paper.getPdfPathName());
		page.put("fileUrl", paper.getPdfUrl());
//		page.put("imageFileName", "");
		page.put("doi", paper.getDoi());
		page.put("affs", paper.getAffilications());
		String pages = paper.getPage();
		if (!StringUtil.isBlank(pages) && pages.contains("-")) {
			String[] pageArr = pages.split("-");
			page.put("startPage", pageArr[0]);
			if (pageArr.length == 2)
				page.put("endPage", pageArr[1]);
		}
			
	}

	private static Paper parsePaper10(Page page, Long taskid, Long issueid) {
		String title = joinText(page, "h3.abs-tit");
		String authors = joinText(page, "p[data-toggle=collapse] span");
		String affs = joinText(page, "address.address ol li");
		Elements keyEles1 = page.select("strong:contains(关键词)");
		String c_keywords = null;
		if (!keyEles1.isEmpty()) {
			c_keywords = keyEles1.first().parent().select("a").text();
		}
		Elements keyEles = page.select("strong:contains(Key words)");
		String e_keywords = null;
		if (!keyEles.isEmpty()) {
			e_keywords = keyEles.first().parent().select("a").text();
		}
		String keywords = String.join("<br>", c_keywords, e_keywords);
		
		Elements abstEles1 = page.select("strong:contains(摘要)");
		String c_abst = null;
		if (!abstEles1.isEmpty()) {
			c_abst = abstEles1.first().parent().ownText();
		}
		Elements abstEles = page.select("strong:contains(Abstract)");
		String e_abst = null;
		if (!abstEles.isEmpty()) {
			e_abst = abstEles.first().parent().ownText();
		}
		String abst = String.join("<br>", c_abst, e_abst);
		String pages = (String) page.get("pages");
		String[] pageArr = pages.split("-");
		
		page.put("title", title);
		page.put("authorName", authors);
		page.put("keywords", keywords);
		page.put("paperAbstract", abst);
		page.put("fileName", "");
		page.put("fileUrl", "");
		page.put("imageFileName", "");
		page.put("doi", page.get("doi"));
		page.put("affs", affs);
		page.put("startPage", pageArr[0]);
		page.put("endPage", pageArr[1]);
		List<String> references = new ArrayList<>();
		page.put("references", references);
		
//		Paper paper = new Paper();
//		paper.setWebsite(page.url());
//		paper.setTitle(title);
//		paper.setTaskid(taskid);
//		paper.setDoi(doi);
//		paper.setAbstracts(abst);
//		paper.setPdfUrl(pdfUrl);
//		paper.setIssueId(issueid);
	
		return null;
	}
	
	private static String joinText(Page page, String selector) {
		List<String> list = page.select(selector).eachText();
		return String.join("<br>", list);
	}
	

	private static List<Author> parseAuthor3(Page page, Long taskid) {
		String[] autArr = page.select("#Lb_Author").text().split(",|，|;|；");
		Set<String> emailSet = page.emailSet();
		String[] emailArr = emailSet.toArray(new String[emailSet.size()]);
		List<Author> list = new LinkedList<>();
		Map<String, String> autEmailMap = Utils.autEmailMap(page.pdfContent(), autArr, emailArr, 0, "\\d");
		autEmailMap.forEach((aut, email) -> {
			Author author = new Author();
			author.setFullName(aut);
			author.setEmail(email);
			author.setTaskId(taskid);
			list.add(author);
		});
		return list;
	}

	
	/**
	 * 铁道科学与工程学报
	 * @author pdz
	 */
	private static Paper parsePaper3(Page page, Long taskid, Long issueid) {
		String title = joinText(page, "#Lb_Title, #Lb_TitleEn");
		String doi = "";
		String keywords = joinText(page, "#Lb_Keywords, #Lb_KeywordsEn");
		String authors = joinText(page, "#Lb_Author, #Lb_AuthorEn");
		String affs = joinText(page, "#Lb_Address, #Lb_AddressEn");
		String abst = joinText(page, "#Lb_Abstract, #Lb_AbstractEn");
		String fileUrl = page.pdfUrl();
		
		Paper paper = new Paper();
		paper.setWebsite(page.url());
		paper.setTitle(title);
		paper.setTaskid(taskid);
		paper.setDoi(doi);
		paper.setAbstracts(abst);
		paper.setPdfUrl(fileUrl);
		paper.setAuthors(authors);
		paper.setAffilications(affs);
		paper.setKeywords(keywords);
		paper.setIssueId(issueid);
		putInfo(page, paper);
		return paper;
	}
	
	private static Paper parsePaper4(Page page, Long taskid, Long issueid) {
		String title = joinText(page, ".J_ZhaiYao_BiaoTi");
		String doi = "";
		String keywords = "";
		String authors = "";
		String affs = "";
		String abstCn = page.select(".J_WenZhang:has(b:contains(摘要)) p").text().replaceFirst("(摘要)+", "").replaceFirst(":+", "").trim();
		String abstEn = page.select(".J_WenZhang:has(b:contains(Abstract)) p").text().replaceFirst("(Abstract)+", "").replaceFirst(":+", "").trim();
		String abst = String.join("<br>", abstCn, abstEn);
		
		Paper paper = new Paper();
		paper.setWebsite(page.url());
		paper.setTitle(title);
		paper.setTaskid(taskid);
		paper.setDoi(doi);
		paper.setAbstracts(abst);
		paper.setAuthors(authors);
		paper.setAffilications(affs);
		paper.setKeywords(keywords);
		paper.setIssueId(issueid);
		putInfo(page, paper);
		return paper;
	}
	
	/**
	 * 地球科学在线
	 * @author pdz
	 * @date 2019年2月26日
	 * @return
	 */
	private static Paper parsePaper5(Page page, Long taskid, Long issueid) {
		String title = joinText(page, ".es_cont.detailpt h2");
		String doi = page.select("#body_lblDoi").text();
		String authors = joinText(page, "#body_lblAuthor, #body_lblEnAuthor");
		String affs = joinText(page, "#body_lblAddress, #body_lblEnAuthorAddress");
		String abst = joinText(page, "#body_lblResumes, #body_lblEnAbstract");
		String keywords = joinText(page, "#body_lblKeyword, #body_lblEnKeyword");
		String pdfUrl = page.select("#body_PDF").first().attr("href");
		
		Paper paper = new Paper();
		paper.setWebsite(page.url());
		paper.setTitle(title);
		paper.setTaskid(taskid);
		paper.setDoi(doi);
		paper.setPdfUrl(pdfUrl);
		paper.setAbstracts(abst);
		paper.setAuthors(authors);
		paper.setAffilications(affs);
		paper.setKeywords(keywords);
		paper.setIssueId(issueid);
		putInfo(page, paper);
		return paper;
	}
	
	/**
	 * 地球科学在线
	 * @author pdz
	 * @date 2019年2月26日
	 * @return
	 */
	private static List<Author> parseAuthor5(Page page, Long taskid) {
		String[] autArr = page.select("#body_lblAuthor").text().split(",|，|;|；");
		String autEmailStr = page.select("#body_lblAuthorIntro").text();
		Map<String, String> autEmailMap = Utils.autEmailMap(autEmailStr, autArr, "\\s");
		
		List<Author> list = new LinkedList<>();
		autEmailMap.forEach((aut, email) -> {
			Author author = new Author();
			author.setFullName(aut);
			author.setEmail(email);
			author.setTaskId(taskid);
			list.add(author);
		});
		return list;
	}
	
	/**
	 * 泰格马克，meta里面没有信息的
	 * @author pdz
	 * @date 2019年2月27日
	 * @return
	 */
	private static Paper parsePaper6(Page page, Long taskid, Long issueid) {
		String title = joinText(page, ".J_ZhaiYao_BiaoTi");
		String doi = "";
		String authors = joinText(page, ".J_ZhaiYao_ZuoZhe");
		String affs = page.select(".J_ZhaiYao_ZuoZhe").stream().map(e -> e.parent().nextElementSibling().nextElementSibling().text()).collect(Collectors.joining("<br>"));
		String abst = joinText(page, ".J_WenZhang:has(b:contains(摘要)), .J_WenZhang:has(b:contains(Abstract))");
		String keywords = String.join(",", page.select(".J_WenZhang_U").eachText());
		Elements pdfEles = page.select(".J_ZhaiYao_ShuXingXiaoLei a.J_VM");
		String pdfUrl = ""; 
		if (!pdfEles.isEmpty())
			pdfUrl = pdfEles.first().attr("href");
		
		Paper paper = new Paper();
		paper.setWebsite(page.url());
		paper.setTitle(title);
		paper.setTaskid(taskid);
		paper.setDoi(doi);
		paper.setPdfUrl(pdfUrl);
		paper.setAbstracts(abst);
		paper.setAuthors(authors);
		paper.setAffilications(affs);
		paper.setKeywords(keywords);
		paper.setIssueId(issueid);
		putInfo(page, paper);
		return paper;
	}
	
	/**
	 * 泰格马克，meta里面没有信息的
	 * @author pdz
	 * @date 2019年2月27日
	 * @return
	 */
	private static List<Author> parseAuthor6(Page page, Long taskid) {
		String[] autArr = page.select(".J_ZhaiYao_ZuoZhe").text().split(",|，|;|；");
		String autEmailStr = page.select(".J_WenZhang").text();
		Map<String, String> autEmailMap = Utils.autEmailMap(autEmailStr, autArr, "\\s|\\d");
		
		List<Author> list = new LinkedList<>();
		autEmailMap.forEach((aut, email) -> {
			Author author = new Author();
			author.setFullName(aut);
			author.setEmail(email);
			author.setTaskId(taskid);
			list.add(author);
		});
		return list;
	}
	
	/**
	 * 陕西师范大学学报自然科学版
	 * @author pdz
	 * @date 2019年2月28日
	 * @return
	 */
	private static Paper parsePaper7(Page page, Long taskid, Long issueid) {
		String title = joinText(page, "td.titledetail");
		String doi = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_Label3").text();
		String authors = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_Label11e").text();
		String affs = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_Label12").text();
		String abst = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_Label2").text();
		String keywords = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_Label4").text();
		String pdfUrl = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_HyperLink1").attr("href");
		
		Paper paper = new Paper();
		paper.setWebsite(page.url());
		paper.setTitle(title);
		paper.setTaskid(taskid);
		paper.setDoi(doi);
		paper.setPdfUrl(pdfUrl);
		paper.setAbstracts(abst);
		paper.setAuthors(authors);
		paper.setAffilications(affs);
		paper.setKeywords(keywords);
		paper.setIssueId(issueid);
		putInfo(page, paper);
		return paper;
	}
	/**
	 * 陕西师范大学学报自然科学版
	 * @author pdz
	 * @date 2019年2月28日
	 * @return
	 */
	private static List<Author> parseAuthor7(Page page, Long taskid) {
		String[] autArr = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_Label11e").text().split(",|，|;|；");
		String autEmailStr = page.select("#ctl00_ContentPlaceHolder1_DetailsView1_Label13").text();
		Map<String, String> autEmailMap = Utils.autEmailMap(autEmailStr, autArr, "\\s|\\d");
		
		List<Author> list = new LinkedList<>();
		autEmailMap.forEach((aut, email) -> {
			if (!StringUtil.isBlank(email)) {
				Author author = new Author();
				author.setFullName(aut);
				author.setEmail(email);
				author.setTaskId(taskid);
				list.add(author);
			}
		});
		return list;
	}
	
	/**
	 * 西南大学学报
	 * @author pdz
	 * @date 2019年2月28日
	 * @return
	 */
	private static Paper parsePaper8(Page page, Long taskid, Long issueid) {
		String title = joinContent(page, "meta[name=dc.title]");
		String doi = page.select("meta[name=dc.identifier]").attr("content");
		Elements autEles = page.select("meta[name=dc.creator]");
		String cn_authors = IntStream.iterate(0, i -> i + 2).limit(autEles.size())
			.filter(i -> i < autEles.size()).mapToObj(i -> autEles.get(i).attr("content"))
			.collect(Collectors.joining(","));
		String en_authors = IntStream.iterate(1, i -> i + 2).limit(autEles.size())
				.filter(i -> i < autEles.size()).mapToObj(i -> autEles.get(i).attr("content"))
				.collect(Collectors.joining(","));
		String authors = String.join("<br>", cn_authors, en_authors);
		String affs = joinText(page, ".affiliation_list");
		String abst = joinContent(page, "meta[name=dc.description]");
		String keywords = joinContent(page, "meta[name=keywords]");
		String pdfUrl = page.select("a:containsOwn(PDF)").attr("href");
		
		Paper paper = new Paper();
		paper.setWebsite(page.url());
		paper.setTitle(title);
		paper.setTaskid(taskid);
		paper.setDoi(doi);
		paper.setPdfUrl(pdfUrl);
		paper.setAbstracts(abst);
		paper.setAuthors(authors);
		paper.setAffilications(affs);
		paper.setKeywords(keywords);
		paper.setIssueId(issueid);
		putInfo(page, paper);
		return paper;
	}
	
	private static List<PaperDoc> parsePaperDoc8(Page page, Long taskid) {
		List<String> references = page.select(".article_reference table tr").eachText();
		page.put("references", references);
		List<PaperDoc> paperDocList = references.stream().filter(ref -> !StringUtil.isBlank(ref)).map(text -> {
			PaperDoc paperDoc = new PaperDoc();
			paperDoc.setDocname(text);
			paperDoc.setTaskid(taskid);
			return paperDoc;
		}).collect(Collectors.toList());
		return paperDocList;
	}
	
	/**
	 * 获取content属性值，并以br标签分隔
	 * @author pdz
	 * @date 2019年2月28日
	 * @param page
	 * @param selector
	 * @return
	 */
	private static String joinContent(Page page, String selector) {
		return joinContent(page, selector, "<br>");
	}
	
	private static String joinContent(Page page, String selector, String delimiter) {
		return page.select(selector).stream().map(e -> e.attr("content")).collect(Collectors.joining(delimiter));
	}

}
